local hx__ninan = fk.CreateSkill {
  name = "hx__ninan",
  tags = { Skill.Compulsory },
}


hx__ninan:addEffect(fk.AfterCardsMove,{
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(hx__ninan.name) then
      for _, move in ipairs(data) do
        if move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              return move.moveReason == fk.ReasonUse or move.moveReason == fk.ReasonResponse
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    for i = 1, #room.draw_pile, 1 do
      local card = Fk:getCardById(room.draw_pile[i])
      if card.is_damage_card then
        table.insertIfNeed(cards, card)
      end
    end
    if #cards > 0 then
      local getcard = cards[math.random(1, #cards)]
      room:obtainCard(player, getcard, true, fk.ReasonDraw, player, hx__ninan.name)
      room:addPlayerMark(player, "@hx__ninan-turn", 1)
    end
  end,
})

hx__ninan:addEffect(fk.CardUsing, {
  is_delay_effect = true,
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(hx__ninan.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local x = 0
    player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function (e)
      local use = e.data
      if use.from == player and use.card.trueName == "slash" then
        x = x + 1
      end
    end, Player.HistoryTurn)
    player.room:setPlayerMark(player, "@hx__ninan_slashcount-turn", x)
  end
})

hx__ninan:addAcquireEffect(function (self, player, is_start)
  local x = 0
  player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function (e)
    local use = e.data
    if use.from == player and use.card.trueName == "slash" then
      x = x + 1
    end
  end, Player.HistoryTurn)
  player.room:setPlayerMark(player, "@hx__ninan_slashcount-turn", x)
end)

hx__ninan:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    local times = player:getMark("@hx__ninan_slashcount-turn")
    if times == 0 then return false end
    if player:getMark("@hx__ninan-turn") >= times then
      return card and card.trueName == "slash"
    end
  end
})


return hx__ninan
